package com.rockxin.cat.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.widget.ImageView;
import android.widget.TextView;

import com.rockxin.cat.R;
import com.rockxin.cat.adapter.PagerAdapter;
import com.rockxin.cat.base.BaseActivity;
import com.rockxin.cat.bean.LendRecordBean;
import com.rockxin.cat.customview.NoScrollViewPager;
import com.rockxin.cat.fragment.LendRecordFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 借款管理
 */
public class BorrowManageActivity extends BaseActivity implements TabLayout.OnTabSelectedListener {
    @BindView(R.id.back_img)
    ImageView backImg;
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.tabLayout)
    TabLayout tabLayout;
    @BindView(R.id.viewPager)
    NoScrollViewPager viewPager;
    private String[] titles = {"还款中", "已结清", "募集中"};
    private List<Fragment> fragmentList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected int setLayout() {
        return R.layout.activity_borrow_manage;
    }

    @Override
    public void initData() {
        title.setText("借款管理");

        fragmentList = new ArrayList<>();
        LendRecordBean lendRecordBean = new LendRecordBean();
        lendRecordBean.setNum("序号");
        lendRecordBean.setName("项目");
        lendRecordBean.setRepay_money("还款金额");
        lendRecordBean.setRepay_time("还款时间");

        fragmentList.add(LendRecordFragment.newInstance(lendRecordBean, 1));
        fragmentList.add(LendRecordFragment.newInstance(lendRecordBean, 2));
        fragmentList.add(LendRecordFragment.newInstance(lendRecordBean, 3));

        viewPager.setAdapter(new PagerAdapter(getSupportFragmentManager(), fragmentList, titles));
        tabLayout.addOnTabSelectedListener(this);
        tabLayout.setupWithViewPager(viewPager);
    }

    @OnClick(R.id.back_img)
    public void onViewClicked() {
        finish();
    }

    @Override
    public void onTabSelected(TabLayout.Tab tab) {
        switch (tab.getPosition()) {
            case 0:
                viewPager.setCurrentItem(0);
                break;
            case 1:
                viewPager.setCurrentItem(1);
                break;
            case 2:
                viewPager.setCurrentItem(2);
                break;
        }
    }

    @Override
    public void onTabUnselected(TabLayout.Tab tab) {

    }

    @Override
    public void onTabReselected(TabLayout.Tab tab) {
        switch (tab.getPosition()) {
            case 0:
                viewPager.setCurrentItem(0);
                break;
            case 1:
                viewPager.setCurrentItem(1);
                break;
            case 2:
                viewPager.setCurrentItem(2);
                break;
        }
    }
}
